﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections.ObjectModel;
using Frogism.Core;
using Frogism.Domain;

namespace Frogism.Web.Controllers
{
    public class WorkoutController : FrogControllerBase
    {

      public WorkoutController() {
        
      }
     
      public ActionResult Index(){
        var rep = new Domain.ActivityUserRepository();
        return View("Index", rep.GetWorkoutDetail(new User() { Id = 1 }));
      }

      public ActionResult Delete(int id) {
        var manager = new Domain.WorkoutManager();
        manager.Delete(id);
        return this.RedirectToAction("Index");
      }
      public ActionResult Update(int Id, int ActivityTypeId, DateTime ActivityDate, int StatusId, decimal Units) {
        var manager = new Domain.WorkoutManager();
        var obj = new Core.WorkOut.Activity();
        obj.Id = Id;
        obj.ActivityType = new Core.WorkOut.ActivityType() { Id = ActivityTypeId };
        obj.ActivityDate = ActivityDate;
        obj.Status =  (Core.WorkOut.ActivityStatus)StatusId;
        obj.Units = Units;
        if (Id <= 0) {
          manager.Create(obj);
        } else {
          manager.Update(obj);
        }
        return RedirectToAction("Index");
      }
      public ActionResult Edit(int id) {
        var manager = new Domain.WorkoutManager();
         Core.WorkOut.IActivity activity ;
        if (id <= 0) {
          activity = manager.DefaultActivity();
        } else {
          activity = manager.GetActivity(id);
        }
        ViewData["ActivityTypeId"] = new SelectList(manager.GetActivityList(), "Id", "Name",activity.ActivityType.Id);
        var statuses = from Core.WorkOut.ActivityStatus s in Enum.GetValues(typeof(Core.WorkOut.ActivityStatus))
                       select new { Id = (int)s, Name = s.ToString() };

        ViewData["StatusId"] = new SelectList(statuses, "Id", "Name", (int)activity.Status);

        return View(activity);
      }
    }
}